package jdkrel._jndi;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
import java.util.Hashtable;

public class jdniDemo {

    public static void main(String[] args) {
        try{
            Hashtable environment= new Hashtable();
            // 加入初始化上下文（InitialContext）实现的工厂类（com.sun.jndi.fscontext.RefFSContextFactory），负责创建InitialContext对象
            environment.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");
            // 通过传入Properties构建InitialContext对象
            InitialContext context = new InitialContext(environment);

            Context cntxt = new InitialContext();
            DataSource ds = (DataSource) cntxt.lookup("jdbc/dpt");
        } catch (NamingException e) {
            e.printStackTrace();
        }
    }
}
